<template>
    <div class="main">
        <left-menu
            class="left-menu"
            :showMenu="showMenu"
        ></left-menu>
        <div class="main-right">
            <top-info></top-info>
            <router-view class="main-wrapper"></router-view>
        </div>
    </div>
</template>

<script>
import TopInfo from "./components/topInfo.vue";
import LeftMenu from "./components/leftMenu.vue";
import { createNamespacedHelpers } from "vuex";

const { mapState, mapMutations } = createNamespacedHelpers("user");
export default {
    name: "main-page",
    components: {
        TopInfo,
        LeftMenu
    },
    computed: {},
    data: () => ({
        showMenu: []
    }),
    created() {
        this.getUserInfo();
    },
    mounted() {},
    watch: {},
    methods: {
        ...mapMutations(["SET_USERINFO"]),
        getUserInfo() {
            this.api
                .getUserInfo() //使用服务器菜单，
                //.getMenuList() //使用本地菜单
                .then(res => {
                    let data = res.data;
                    let menu = data.menu;
                    let userInfo = Object.assign({}, data.user.plugininfo, {
                        userid: data.user.userid,
                        username: data.user.username
                    });
                    // 加上权限信息
                    let roleIdsStr = userInfo.roleIds;
                    let roleArr = roleIdsStr && roleIdsStr.split(",");

                    const adminRoleId = "1"; // 超管
                    const operatorRoleId = "2"; // 运营
                    const maintenanceRoleId = "3"; // 运维
                    const businessRoleId = "4"; // 商务
                    userInfo.isAdmin =
                        roleArr &&
                        roleArr.length &&
                        roleArr.some(item => item === adminRoleId);
                    userInfo.isOperator =
                        roleArr &&
                        roleArr.length &&
                        roleArr.some(item => item === operatorRoleId);
                    userInfo.isMaintenance =
                        roleArr &&
                        roleArr.length &&
                        roleArr.some(item => item === maintenanceRoleId);
                    userInfo.isBusiness =
                        roleArr &&
                        roleArr.length &&
                        roleArr.some(item => item === businessRoleId);

                    this.SET_USERINFO(userInfo);
                    this.showMenu = menu;
                    //this.showMenu = data;
                })
                .catch(err => {});
        }
    }
};
</script>

<style lang="scss" src="../../assets/styles/main/index.scss"></style>